package com.poor.user.service.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 字符串工具类
 */
public class StringUtils {
    private static final String only_letter_number = "^[a-zA-Z][a-zA-Z0-9_]{6,13}$";
    private static final String phone_valid = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))|(19[9]))\\\\d{8}$";

    /**
     * 字符串是否为空
     *
     * @param str 字符串
     * @return true--为空，false--不为空
     */
    public static boolean isEmpty(CharSequence str) {
        if (str == null || str.length() == 0)
            return true;
        else
            return false;
    }

    /**
     * 判断是否符合一般账号的规则
     *
     * @param userAccountNo 账号
     * @return true--账号符合规则,false--账号不符合规则
     */
    public static boolean isUserAccountNo(String userAccountNo) {
        Pattern pattern = Pattern.compile(only_letter_number);
        Matcher m = pattern.matcher(userAccountNo);
        if (m.matches()) {
            return true;
        }
        return false;
    }

    /**
     * 判断是否符合密码标准
     *
     * @param userPassWord 电话号码
     * @return true--密码符合规则,false--密码不符合规则
     */
    public static boolean isUserPassWord(String userPassWord) {
        Pattern pattern = Pattern.compile(only_letter_number);
        Matcher m = pattern.matcher(userPassWord);
        if (m.matches()) {
            return true;
        }
        return false;
    }

    /**
     * 判断是否是电话号码
     *
     * @param phone 电话号码
     * @return true--电话符合规则,false--不符合电话规则
     */
    public static boolean isPhone(String phone) {
        Pattern pattern = Pattern.compile(phone_valid);
        Matcher m = pattern.matcher(phone);
        if (m.matches()) {
            return true;
        }
        return false;
    }
}
